package com.zy.ivideo.controller;

import com.zy.ivideo.entity.CommentEntity;
import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.service.CommentService;
import com.zy.ivideo.token.PassToken;
import com.zy.ivideo.token.UserToken;
import com.zy.ivideo.utils.ResponseUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@Api(value = "评论模块API接口", description = "该模块提供评论模块服务", tags = "评论模块")
public class CommentController {

    @Autowired
    CommentService service;

    /**
     * 发布评论
     * @param entity
     * @return
     */
    @UserToken
    @ApiOperation(value = "发布评论", notes = "发布评论", httpMethod = "POST")
    @PostMapping("/publishComment")
    public ResponseEntity<CommentEntity> publishComment(@RequestBody
                                                            @ApiParam(value = "评论实体", name = "entity", required = true)
                                                                    CommentEntity entity){
       return service.publishComment(entity);
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @UserToken
    @ApiOperation(value = "删除评论", notes = "删除评论", httpMethod = "DELETE")
    @DeleteMapping("/removeComment")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "Long", name = "id", value = "评论id", required = true),
    })
    public ResponseEntity<Boolean> removeComment(Long id){
       return service.removeComment(id);
    }

    /**
     * 获取评论信息
     * @param datatype
     * @param itemid
     * @return
     */
    @PassToken
    @ApiOperation(value = "获取评论信息", notes = "获取评论信息", httpMethod = "GET")
    @GetMapping("/getCommentByUserId")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "int", name = "datatype", value = "数据类型 0-simplevideo 1-multitypevideo", required = true),
            @ApiImplicitParam(dataType = "String", name = "itemid", value = "资源id", required = true)
    })
    public ResponseEntity<List<CommentEntity>> getCommentById(int datatype, String itemid){
        return service.getCommentById(datatype,itemid);
    }

    /**
     * 点赞
     * @param commentid
     * @return
     */
    @UserToken
    @ApiOperation(value = "点赞", notes = "点赞", httpMethod = "POST")
    @PostMapping("/agree")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "int", name = "commentid", value = "评论id", required = true),
    })
    public ResponseEntity<Boolean> agree(int commentid){
        return service.agree(commentid);
    }

    /**
     * 取消点赞
     * @param commentid
     * @return
     */
    @UserToken
    @ApiOperation(value = "取消点赞", notes = "取消点赞", httpMethod = "POST")
    @PostMapping("/unAgree")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(dataType = "int", name = "commentid", value = "评论id", required = true),
    })
    public ResponseEntity<Boolean> unAgree(int commentid){
        return service.unAgree(commentid);
    }
}
